package com.hotelsystem.reservations.main;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

/**
 * Class providing menues for the main window
 * @author Viktor Mitev
 *
 */
public class MainMenuView {

	private JMenuBar mainMenuBar;
	private JMenu fileMenu;
	private JMenu clientsMenu;
	private JMenu roomsMenu;
	private JMenu reservationsMenu;
	private JMenuItem homeFileItem;
	private JMenuItem closeFileItem;
	private JMenuItem addClientItem;
	private JMenuItem viewClientsItem;
	private JMenuItem addRoomItem;
	private JMenuItem viewRoomsItem;
	private JMenuItem addReservationItem;
	private JMenuItem viewReservationsItem;
	
	public JMenuBar getMainMenuBar() {
		return mainMenuBar;
	}

	public MainMenuView() {
		buildUI();
	}

	private void buildUI() {
		mainMenuBar = new JMenuBar();
		
		fileMenu = new JMenu("File");
		fileMenu.setMnemonic(KeyEvent.VK_F);
		
		clientsMenu = new JMenu("Clients");
		clientsMenu.setMnemonic(KeyEvent.VK_C);
		
		roomsMenu = new JMenu("Rooms");
		roomsMenu.setMnemonic(KeyEvent.VK_O);
		
		reservationsMenu = new JMenu("Reservations");
		reservationsMenu.setMnemonic(KeyEvent.VK_R);
		
		homeFileItem = new JMenuItem("Home");
		fileMenu.add(homeFileItem);
		fileMenu.addSeparator();
		
		closeFileItem = new JMenuItem("Close");
		fileMenu.add(closeFileItem);
		closeFileItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		
		addClientItem = new JMenuItem("New client");
		viewClientsItem = new JMenuItem("View clients");
		clientsMenu.add(addClientItem);
		clientsMenu.add(viewClientsItem);
		
		addRoomItem = new JMenuItem("New room");
		viewRoomsItem = new JMenuItem("View rooms");
		roomsMenu.add(addRoomItem);
		roomsMenu.add(viewRoomsItem);
		
		addReservationItem = new JMenuItem("New reservation");
		viewReservationsItem = new JMenuItem("View reservations");
		reservationsMenu.add(addReservationItem);
		reservationsMenu.add(viewReservationsItem);
		
		mainMenuBar.add(fileMenu);
		mainMenuBar.add(clientsMenu);
		mainMenuBar.add(roomsMenu);
		mainMenuBar.add(reservationsMenu);
	}
	
	public void setCloseItemListener(ActionListener listener) {
		closeFileItem.addActionListener(listener);
	}
	
	public void setAddClientItemListener(ActionListener listener) {
		addClientItem.addActionListener(listener);
	}
	
	public void setViewClientsListener(ActionListener listener) {
		viewClientsItem.addActionListener(listener);
	}
	
	public void setAddRoomItemListener(ActionListener listener) {
		addRoomItem.addActionListener(listener);
	}
	
	public void setViewRoomsListener(ActionListener listener) {
		viewRoomsItem.addActionListener(listener);
	}
	
	public void setAddReservationItemListener(ActionListener listener) {
		addReservationItem.addActionListener(listener);
	}
	
	public void setViewReservationsListener(ActionListener listener) {
		viewReservationsItem.addActionListener(listener);
	}
	
	public void setHomeListener(ActionListener listener)
	{
		homeFileItem.addActionListener(listener);
	}

	public JPanel getHomePanel(){
		JLabel result = new JLabel();
		result.setText("Welcome To The Hotel System!");
		result.setFont(new Font("Serif", Font.BOLD, 16));
		result.setForeground(new Color(51, 0, 102));
		JPanel mainPanel = new JPanel();
		FlowLayout mainLayout = new FlowLayout();
		mainPanel.setLayout(mainLayout);
		mainPanel.add(result);
		return mainPanel;
	}
}
